<?php
/**
 * Created by PhpStorm.
 * User: MACD
 * Date: 14-7-22
 * Time: 下午9:22
 */
class User_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function is_user($name)
    {
        $query = $this->db->get_where('USERS', array('USER_NAME'=>$name), 1, 0);
        if($query->num_rows()>0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public function set_user($arr)
    {
        $arr['LOGIN_TIME'] = date('Y-m-d H:i:s');
        return $this->db->insert('USERS', $arr);
    }

    public function get_user_name($name)
    {
        $query = $this->db->get_where('USERS', array('USER_NAME'=>$name), 1, 0);
        if($query->num_rows()==1)
        {
            return $query->row_array();
        }
        else
        {
            return false;
        }
    }

    public function update_time($id)
    {
        $time = date('Y-m-d H:i:s');
        $this->db->where('USER_ID', $id);
        return $this->db->update('USERS', array('LOGIN_TIME'=>$time));
    }
}